package com.cq.oa.web.mat.action;

import java.util.List;

import oa.base.session.SessionManger;
import oa.base.util.Constants;
import oa.base.util.Page;
import oa.base.web.Action.BaseAction;

import com.cq.oa.domain.mat.MatOffice;
import com.cq.oa.service.mat.MatOfficeService;

public class MatOfficeAction extends BaseAction<MatOffice>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 2283944864146115800L;
	
	private MatOfficeService matOfficeService;
	

	public void setMatOfficeService(MatOfficeService matOfficeService) {
		this.matOfficeService = matOfficeService;
	}

	@Override
	protected Class<MatOffice> getEntityClass() {
		return MatOffice.class;
	}
	
	public String findByPage() throws Exception {
		filterMap.put("orgSid", SessionManger.getOrgId());
		filterMap.put(Constants.WHERE_LIKE+"cname", entity.getCname());
		Page<MatOffice> offices = matOfficeService.findByPage(filterMap, linkMap,shortMap, super.getPageNo(),super.getPageSize());
		this.renderJsonSuccess(jsonUtils.getExtJson(offices, new String[] {}));
		return JSON;
	}
	public String operate(){
		if(null!=entity.getSid()){
			entity = matOfficeService.findByParmkeys(entity.getSid());
		}
		return "operate";
	}
	
	public String save(){
		if(null!=entity.getSid()){
			this.matOfficeService.update(entity);
		}else{
			this.matOfficeService.create(entity);
		}
		this.renderJsonSuccess();
		return JSON;
	}
	
	public String delete(){
		this.matOfficeService.delete(entity.getSid());
		this.renderJsonSuccess();
		return JSON;
	}
	/**
	 * 物品领用
	 * @return
	 * lilang 
	 * 2013-10-11下午1:03:34
	 */
	public String use(){
		return "use";
	}
	/**
	 * 物品采购
	 * @return
	 * lilang 
	 * 2013-10-11下午1:03:34
	 */
	public String purchase(){
		return "purchase";
	}
	
	/**
	 * 物品采购申请单
	 * @return
	 * lilang 
	 * 2013-10-11下午1:03:34
	 */
	public String apply(){
		filterMap.put("orgSid", SessionManger.getOrgId());
		List<MatOffice> matOffices = this.matOfficeService.findParByList(filterMap);
		this.putKey.put("matOffices", matOffices);
		return "apply";
	}
	
	/**
	 * 物品领用申请单
	 * @return
	 * lilang 
	 * 2013-10-11下午1:03:34
	 */
	public String useApply(){
		filterMap.put("orgSid", SessionManger.getOrgId());
		List<MatOffice> matOffices = this.matOfficeService.findParByList(filterMap);
		this.putKey.put("matOffices", matOffices);
		return "useApply";
	}
	
}
